#include <reg52.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long uint32;
sbit ENLED = P1^4;
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;

code uint8 str[]={	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
					0xFF,0xFF,0xBD,0x81,0x81,0xBD,0xFF,0xFF,
					0xF3,0xC1,0x81,0x03,0x03,0x81,0xC1,0xF3,
					0xFF,0xC1,0x81,0xBF,0xBF,0x81,0xC1,0xFF,
					0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
				};
uint8 index;
uint16 counter;

//定时器初始化
void timer0_init()
{
	TMOD|=0x01;
	TMOD&=0xfd;
	TR0=1;
	TH0=0xfc;
	TL0=0x67;
}
//中断初始化
void int_init()
{
	EA=1;
	ET0=1;
}

//刷新led
void refresh_Led()
{
	static uint8 j=0;
	switch(j)
	{
		case 0:ADDR0=0;ADDR1=0;ADDR2=0;break;
		case 1:ADDR0=1;ADDR1=0;ADDR2=0;break;
		case 2:ADDR0=0;ADDR1=1;ADDR2=0;break;
		case 3:ADDR0=1;ADDR1=1;ADDR2=0;break;
		case 4:ADDR0=0;ADDR1=0;ADDR2=1;break;
		case 5:ADDR0=1;ADDR1=0;ADDR2=1;break;
		case 6:ADDR0=0;ADDR1=1;ADDR2=1;break;
		case 7:ADDR0=1;ADDR1=1;ADDR2=1;break;
		default:break;
	}
	P0=str[j+index];
	if(7==j++)
	{
		j=0;
	}
}

void main()
{
	ENLED=0;ADDR3=0;
	index=0;
	counter=0;
	timer0_init();
	int_init();
	while(1);
}

void interruptLed() interrupt 3
{
	TH0=0xfc;
	TL0=0X67;
	counter++;
	if(200==counter)
	{
		index++;
		if(32==index)
		{
			index=0;
		}
		counter=0;
	}
	refresh_Led();
}